package Demo;

import java.io.*;
import java.lang.reflect.Method;

public class Demo74 extends ClassLoader {
    public static void main(String[] args)throws Exception {
        methodClassLoader m=new methodClassLoader();
        Class<?> cls = m.loaderDate("Text");
        Object obj = cls.getDeclaredConstructor().newInstance();
        Method send = cls.getDeclaredMethod("send");
        send.invoke(obj);
    }

}

class methodClassLoader extends ClassLoader {
    public static final String MESSAGE_PATH = "D:" + File.separator + "Java"+ File.separator+"Text.class";

    public Class<?> loaderDate(String className) throws Exception {
        byte[] data = this.loadClassData();
        if (data != null) {
            return super.defineClass(className, data, 0, data.length);
        }
        return null;
    }

    private byte[] loadClassData() throws Exception {
        InputStream input = null;
        ByteArrayOutputStream bos = null;
        byte[] date = null;
        try {
            input = new FileInputStream(MESSAGE_PATH);
            bos = new ByteArrayOutputStream();
            input.transferTo(bos);
            date = bos.toByteArray();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (input != null) {
                input.close();
            }
            if (bos != null) {
                bos.close();
            }
        }
        return date;
    }
}


